package com.zhongyi.controller;

import com.zhongyi.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/testVoid")
    public void testVoid(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        // 编写请求转发的程序
//        request.getRequestDispatcher("/WEB-INF/pages/success.jsp").forward(request,response);

        // 重定向
//        response.sendRedirect(request.getContextPath()+"/response.jsp");

        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");

        response.getWriter().print("你好，世界!");
    }


    @RequestMapping("/testAjax")
    @ResponseBody
    public User testAjax(@RequestBody User user){
        System.out.println("user===="+user);
        user.setUsername("hahahahaha");
        user.setAge(60);
        return user;
    }

}
